﻿using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.Common.C_Enum;
using STHPMS1.ICore.I_Entity.Stmpms1;
using STHPMS1.ICore.I_Serv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using STHPMS1.Common.C_Extension;

namespace STHPMS1.BLL.B_Serv
{
    public class ModelCalculateService : IModelCalculateService
    {
        public static IModelCalculateService CreateServiceByModel(IDm_Modelgroup model)
        {
            IEquation1Service serv = null;
            if ((model.Modelmode_Dictid ?? 0) == ModelFormEnum.M821.GetEnumValue())
            {
                serv = new Equation1Service() { 
                    Model=model
                };
            }
            return serv;

        }

        public virtual double CalculateY(double x)
        {
            return 0;
        }

        public virtual double CalculateX(double y)
        {
            return 0;
        }

        public virtual string PrintForumla()
        {
            return "";
        }


        public IDm_Modelgroup Model
        {
            get;
            private set;
        }
    }

    public class Equation1Service : ModelCalculateService,IEquation1Service
    {
        public double A
        {
            get
            {
                if (this.Model == null) return 0;
                return this.Model.Formulacoeff1??0;
            }
        }


        public double B
        {
            get
            {
                if (this.Model == null) return 0;
                return this.Model.Formulacoeff2 ?? 0;
            }
        }

        public override double CalculateY(double x)
        {
            return A*x+B;
        }

        public override double CalculateX(double y)
        {
            return (y-B) / A;
        }

        public override string PrintForumla()
        {
            return string.Format("y={0:F2}x+{1:F2}", A,B);
        }

    }

}
